<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<button open-type="getUserInfo" @getuserinfo="login">登录授权</button>
	</view>
</template>

<script>
	export default {
		methods: {
			login() {		
				uni.login({
					success(res) {	
						console.log('success: ' , res)
						this.$api.post({
							url: '/open/user/wx/login',
							data: {
								code: res.code,
								clientId: "wxmp",
								clientSecret: "123456"
							}
						}).then(loginResp => {
							this.$userInfo.setUserInfo(loginResp.data.data)
							this.$userInfo.updateLoginStatus(true)
							uni.navigateBack({})	
							uni.showToast({
								icon: 'none',
								title: '您好，' + loginResp.data.data.username
							})
							this.$websocket.connet()
							console.log('login success: ', loginResp)
						}).catch(loginResp => {
							console.log('login fail: ', loginResp)
						})
					},
					fail(res) {
						console.log('fail: ' , res)
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
